A utility for C++ programmers who wish to calculate simple source code metrics including:
• Lines of Code
• Lines containing comments
• Number of Classes
• Number of Methods
• A simple measure of complexity
The program is simple to use. Run it and drag files or folders of files from the Finder™ to the main window. Then choose Measure to have the program measure each text file and calculate totals for the whole collection.
The collection document can be saved and then re-measured again later after the programmer has done more work.
The list of files and their individual statistics can be sorted to quickly point you to particular files that are getting too fat and complex.
This software is PostCardWare, (free really).
Details
Ok, now the bad news... this is a very simple implementation. I’ve looked at what’s involved in measuring code complexity properly and even had a stab at a recursive descent parser for c++ but basically I would need to handle the searching and processing of #include files, the pre-processor, and full parsing of modern c++ to do this properly.
So, what I’ve done so far is to provide the infrastructure that can process a collection of files. The implementation here simply reads each file, line by line, and scores on a number of points:
Lines = non-empty lines in each file.
Comments = lines containing comments.
Classes = lines with the word “class” in them!
Methods = lines that look like a method implementation.
Complexity = lines containing “if”, “else”, “switch”, or “case”.
I’m embarrassed just telling you this. But some sort of consistent measure is better than none at all. To see the gory details of how the program parsed your file, double-click it in the main window and it will open in a window with some symbols down the left margin.
L = Counted as a line of code
* = Counted as a comment line
C = Counted as a class declaration
M = Counted as a method implementation
! = Counted as 1 point of complexity
Use
Launch the program, drag either a collection of text files or folders of files into the body of the main window. The files you dragged in will be added or if folders were dragged in they will be recursively searched for all TEXT files.
Note that if you plan to add folders with large numbers of files (like all of MacApp for example) you’ll need to give the program more memory or it will run out and complain.
By default the sorting is by the name of each file. You can sort by other things by clicking the headings as you would in the Finder. The “pyramid” icon at the top right can be clicked to reverse the sort order.
Under the File menu there is a Save As Text… option which will save a report to a text file.
Credits and “payment”
Peter Marks wrote the program.
Metrowerks Codewarrior 9 C++ was the compiler.
MacApp Release 11 is the framework.
Jim Luther and Apple DTS for MoreFiles.
Now, if you’d like to encourage me to produce more free software please send me a postcard on a technical theme and send it to:
Access Informatics
6 Donegal Road
Killarney Heights 2087
Australia
I’m keen to get feedback from people who might use this tool. Please send comments and suggestions to peter.marks@pobox.com